package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Goods;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author tongatong
 * @name SupplierController
 * @description
 * @date 2021/10/14
 * @time 17:10
 */
@RestController
@RequestMapping("/supplier")
public class SupplierController {
    @Resource
    private SupplierService supplierService;

    @PostMapping("list")
    public Map<String,Object> list(Integer page, Integer rows, String supplierName) {
        Map<String, Object> result = new HashMap<>();

        PageInfo<Supplier> supplierPageInfo = supplierService.getSupplierList(page, rows, supplierName);
        result.put("total", supplierPageInfo.getTotal());
        result.put("rows", supplierPageInfo.getList());
        return result;
    }
    @PostMapping("/save")
    public ServiceVO<Void> save(Supplier supplier, Integer supplierId) {
        /*System.out.println("------------------------");
        System.out.println(supplierId);
        System.out.println(supplier.toString());
        System.out.println("------------------------");*/

        supplierService.save(supplier, supplierId);

        return new ServiceVO<>(SuccessCode.SUCCESS_CODE, SuccessCode.SUCCESS_MESS);
    }
    @PostMapping("delete")
    public ServiceVO<Void> delete(String  ids) {
        /*System.out.println("------------------");
        //ids数据格式：14,15
        System.out.println(ids);
        System.out.println("------------------");*/

        supplierService.delete(ids);

        return new ServiceVO<>(SuccessCode.SUCCESS_CODE, SuccessCode.SUCCESS_MESS);
    }
}
